
#include "string_ext.h"

StringExt::StringExt(void):string() {}
StringExt::StringExt(const size_t& len, const char& c):string(len, c) {}
StringExt::StringExt(const char* s):string(s) {}
StringExt::StringExt(const string& s):string(s) {}
StringExt::StringExt(const StringExt& s):string(s.data()) {}

vector<StringExt> StringExt::split( const string& splitter ) const
{
	vector<StringExt> v;

	if ( this->empty() )
		return v;

	size_t sp_len = splitter.size();

	string tmp = *this;
	tmp += splitter;

	size_t index = 0;
	while( (index = tmp.find_first_of(splitter)) != string::npos )
	{
		v.push_back( tmp.substr(0, index) );
		if ( tmp == splitter )
			break;
		tmp = tmp.substr(index + sp_len);
	}

	return v;
}

StringExt StringExt::upper( void ) const
{
	StringExt result;

	for(size_t i = 0; i < this->size(); i++)
	{
		char cur = this->data()[i];
		if( isalpha(cur) )
			result += StringExt(1, cur & 0XDF);
		else
			result += StringExt(1, cur);
	}
	return result;
}

StringExt StringExt::lower( void ) const
{
	StringExt result;

	for(size_t i = 0; i < this->size(); i++)
	{
		char cur = this->data()[i];
		if( isalpha(cur) )
			result += StringExt(1, cur | 0X20);
		else
			result += StringExt(1, cur);
	}
	return result;
}